package com.mvc.web.common.utils;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

/** 
 * @Description: 短信平台
 * @author: 白海安(baiha@jizhicar.com) 2017年8月28日 上午10:24:53
 * @version V1.0
 */
public class SMSUtil {
	
	private static final String  AppCode="2f971ac1ca6a4d30a638a059b9e556fa";
	private static final String  Host="http://ali-sms.showapi.com";
	private static final String  Method="get";
	
	private static final String  title ="货运巴巴";
//	private static final String  content ="尊敬的用户您好,欢迎您使用货运巴巴产品,您的验证码是[code],有效期为[time]分钟。";
	private static final String  content ="尊敬的用户您好,欢迎您下载货运巴巴App时刻关注您的货运单信息。下载地址为：[url]";
	private static final String  notiPhone ="13522940083";
	
	/** 
	 * @Description: 发送短信 
	 * @author 白海安(baiha@jizhicar.com) 2017年8月28日 上午11:12:17
	 * @version V1.0
	 */
	public static void sendSms(String jsonData,String phone,String tNum){
	    String path = "/sendSms";
	    Map<String, String> headers = new HashMap<String, String>();
	    //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
	    headers.put("Authorization", "APPCODE " + AppCode);
	    Map<String, String> querys = new HashMap<String, String>();
	    querys.put("content", jsonData);
	    querys.put("mobile", phone);
	    querys.put("tNum", tNum);
	    try {
	    	/**
	    	* 重要提示如下:
	    	* HttpUtils请从
	    	* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
	    	* 下载
	    	*
	    	* 相应的依赖请参照
	    	* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
	    	*/
	    	HttpResponse response = HttpUtils.doGet(Host, path, Method, headers, querys);
	    	System.out.println(response.toString());
	    	//获取response的body
	    	//System.out.println(EntityUtils.toString(response.getEntity()));
	    } catch (Exception e) {
	    	e.printStackTrace();
	    }
	}
	
	/** 
	 * @Description: 创建模板 
	 * @author 白海安(baiha@jizhicar.com) 2017年8月28日 上午10:42:26
	 * @version V1.0
	 */
	public static void createTemplate(){
	    String path = "/createTemplate";
	    Map<String, String> headers = new HashMap<String, String>();
	    //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
	    headers.put("Authorization", "APPCODE " + AppCode);
	    Map<String, String> querys = new HashMap<String, String>();
	    querys.put("content", content);
	    querys.put("notiPhone", notiPhone);
	    querys.put("title", title);
	    try {
	    	/**
	    	* 重要提示如下:
	    	* HttpUtils请从
	    	* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
	    	* 下载
	    	*
	    	* 相应的依赖请参照
	    	* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
	    	*/
	    	HttpResponse response = HttpUtils.doGet(Host, path, Method, headers, querys);
	    	System.out.println(response.toString());
	    	//获取response的body
	    	System.out.println(EntityUtils.toString(response.getEntity()));
	    } catch (Exception e) {
	    	e.printStackTrace();
	    }
	}
	
	public static void main(String[] args){
		createTemplate();
	}
	
}
